package tree.leetcode_101_easy;

import java.util.ArrayList;
import java.util.List;

public class IsSymmetric {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.right = new TreeNode(3);
        root.right = new TreeNode(2);
        root.right.right = new TreeNode(3);
        System.out.println(isSymmetric(root));
    }
    public static boolean isSymmetric(TreeNode root){
        if(root == null){
            return true;
        }
        return dfs(root.left,root.right);
    }
    public static boolean dfs(TreeNode left,TreeNode right){
        if(left == null && right == null){
            return true;
        }
        if(left == null || right == null){
            return false;
        }
        if(left.val != right.val){
            return false;
        }
        //对称的条件是，左子树左孩子 == 右子树右孩子 && 左子树右孩子 == 右子树左孩子
        return dfs(left.left,right.right) && dfs(left.right,right.left);
    }
}
